﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuartzTypeLib;

// http://code-life.net/?p=1521

namespace mp4player
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = @"c:\";
            openFileDialog.Filter = "メディアファイル(*.avi;*.mpg;*.wmv)|*.avi;*.mpg;*.wmv|すべてのファイル|*.*";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FilgraphManager filgraphManager = new FilgraphManager();
                filgraphManager.RenderFile(openFileDialog.FileName);
                IBasicVideo bv = (IBasicVideo)filgraphManager;
                IVideoWindow vw = (IVideoWindow)filgraphManager;
                IMediaEventEx mevent = (IMediaEventEx)filgraphManager;

                int vx, vy;
                bv.GetVideoSize(out vx, out vy);

                vw.Owner = (int)this.Handle;
                vw.WindowStyle = 0x40000000 | 0x4000000;

                vw.SetWindowPosition(0, 0, vx, vy);
                this.Width = vx + 2;
                this.Height = vy + 55;
                button1.Location = new Point(button1.Location.X, vy + 2);

                mevent.SetNotifyWindow((int)this.Handle, 0x8000, 0);

                filgraphManager.Run();
            }
        }
    }
}
